<?php

namespace app\admin\model\vactivities;

use think\Model;


class Serimange extends Model
{

    

    

    // 表名
    protected $table = 'activity';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'startTime_text',
        'isrecording_text',
        'delTime_text',
        'endTime_text',
        'status_text',
    ];

    //新加状态字段
    public function getStatusList()
    {
        return ['0' => __('activity_status 0'),'1' => __('activity_status 1'),'2' => __('activity_status 2')];
    }
    //获取状态字段
    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    
    public function getIsrecordingList()
    {
        return ['1' => __('Isrecording 1'), '0' => __('Isrecording 0')];
    }


    public function getStarttimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['startTime']) ? $data['startTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIsrecordingTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['isrecording']) ? $data['isrecording'] : '');
        $list = $this->getIsrecordingList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDeltimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['delTime']) ? $data['delTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getEndtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['endTime']) ? $data['endTime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setStarttimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setDeltimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    protected function setEndtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
